<?php


namespace app\api\controller;

use app\api\business\User as UserBus;

class User extends AuthBase
{
    public function index(){
        $user = new UserBus();
        $res = $user->getUserByIdBus($this->userId);
        $resultUser = [
            "id" => $this->userId,
            "username" => $res["username"],
            "sex" => $res["sex"],
            "create_time" => $res["create_time"],
            "update_time" => $res["update_time"],
            "status" => $res["status"],
            "phone_number" => $res["phone_number"]
        ];
        return show(config("status.success"),"获取成功",$resultUser);
    }
    public function update(){
        $username = input("param.username","","trim");
//        $username = $this->request->param("username");
        $sex = input("param.sex","0","intval");
//        dump($username);exit();
        $data = [
            "username" => $username,
            "sex" => $sex
        ];
        $validate = new \app\api\validate\User();
        $validateRes = $validate->scene("user_update")->check($data);
        if(!$validateRes){
            return show(config("status.error"), $validate->getError());
        }
        $userObject = new UserBus();
        $userObject->getUserByUsernameBus($this->userId,$data);
        if(!$userObject){
            return show(config("status.error"),"数据未更新");
        }
        return show(config("status.success"),"数据更新成功");
    }
}